package com.hskn.hss.module.tldictattentionitem.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.tldictattentionclass.entity.TlEmergentDictAttentionClass;
import com.hskn.hss.module.tldictattentionitem.entity.TlEmergentDictAttentionItem;
import com.hskn.hss.module.tldictattentionitem.mapper.TlEmergentDictAttentionItemMapper;
import com.hskn.hss.module.tldictattentionitem.service.ITlEmergentDictAttentionItemService;
import com.hskn.hss.module.tlequip.mapper.TlEquipMapper;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-18
 */
@Slf4j
@RestController
@RequestMapping("/hss/tlattentionitem")
public class TlEmergentDictAttentionItemController {

    @Autowired
    ITlEmergentDictAttentionItemService tlEmergentDictAttentionItemService;

    @SysLog(businessType = BusinessType.INSERT, tableName = "tl_emergent_dict_attention_item", bean = TlEmergentDictAttentionItem.class, beanMapper = TlEmergentDictAttentionItemMapper.class, names = "equipname")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlEmergentDictAttentionItemService.insert(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_emergent_dict_attention_item", idKey = "id", bean = TlEmergentDictAttentionItem.class, beanMapper = TlEmergentDictAttentionItemMapper.class, names = "equipname")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlEmergentDictAttentionItemService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    @SysLog(businessType = BusinessType.UPDATE, tableName = "tl_emergent_dict_attention_item", idKey = "id", bean = TlEmergentDictAttentionItem.class, beanMapper = TlEmergentDictAttentionItemMapper.class, names = "equipname")
    @RequestMapping(value = "deletebyid", method = RequestMethod.POST)
    public AjaxResult<Object> deletebyid(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            return tlEmergentDictAttentionItemService.deletebyid(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("删除失败，请稍后再试");
        }
    }

    @RequestMapping(value = "getSelectList", method = RequestMethod.POST)
    public AjaxResult<Object> getSelectList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        return AjaxResult.success(tlEmergentDictAttentionItemService.getSelectList(params.getString("classid")));
    }

    @RequestMapping(value = "getDetail", method = RequestMethod.POST)
    public AjaxResult<Object> getDetail(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        TlEmergentDictAttentionItem tlEmergentDictAttentionItem = null;
        try {
            tlEmergentDictAttentionItem = tlEmergentDictAttentionItemService.getDetail(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }
        return AjaxResult.success(tlEmergentDictAttentionItem);

    }

    @RequestMapping(value = "getList", method = RequestMethod.POST)
    public AjaxResult<Object> getList(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            JSONObject json = tlEmergentDictAttentionItemService.getList(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }
}

